<template>
  <div style="width: 100%;height: auto">
    <div id="deawer">
      <v-tableTitle
        :btnConfig="btnConfig"
        @cancel="cancel"
        @save="save"
      ></v-tableTitle>
      <div class="detailBox">
        <v-detail ref="detail"></v-detail>
      </div>
    </div>
  </div>
</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import skipMixin from "@/mixins/SkipMixin";

import tableTitle from "commons/TableTitle";
import detail from "../details/Detail";


export default {
  name: "",
  mixins: [baseMixin, skipMixin],
  data () {
    return {
      newFlag: false,
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.save'),certigier: !this.btnPermNameList.includes('EN020106')&&!this.btnPermNameList.includes('WM030106'), invalid: "save" },
        { label: this.$t('common.cancel'),certigier: !this.btnPermNameList.includes('EN020107')&&!this.btnPermNameList.includes('WM030107'), invalid: "cancel" }
      ]

    }
  },
  created () {
  },
  methods: {
    //保存按钮
    save () {
      this.$refs.detail.$children[1].$refs.input.$refs["from"].validate(async (valid) => {
        if (valid) {
          let url = ""
          let data = this.$refs.detail.detailData;
          if (this.newFlag) {
            url = "/insertSku";
          } else {
            url = "/updateSku"
          }
          data.whseid = this.$store.state.wms
          if(!data.class_name){
            return this.$message.error(this.$inputPlease("common.class"))
          }
          try {
            let res = await this.$api.post(url, data);
            
              this.$message({
                message: res.returnMgr,
                showClose: true,
                type: 'success'
              })
              this.cancel();
          } catch (e) {
            this.$message.error(e);
          }
        }
      });

    },
    //弹框取消
    cancel () {
      this.$router.push({ name: "sku" });
    }
  },
  mounted () {
    this.newFlag = this.$store.state.newFlag;
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.newFlag = data.newFlag;
    }
    if (this.$store.state.wms.toUpperCase().includes('WMWHSE')) {
      this.$refs.detail.pushMenu()
    }
  },
  watch: {},
  components: {
    "v-tableTitle": tableTitle,
    "v-detail": detail,
  }
};
</script>

<style scoped>
</style>
